package com.expense.dwr;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.http.HttpSession;

import uk.ltd.getahead.dwr.WebContext;
import uk.ltd.getahead.dwr.WebContextFactory;

import com.expense.dao.Dao;
import com.expense.entity.TeamInfo;
import com.expense.entity.UserInfo;
import com.expense.services.BasicServices;

public class GetTeamDwr {
	private BasicServices basicServices=new BasicServices();
	
	public List<TeamInfo> teamList(){
		WebContext webContext=WebContextFactory.get();
		HttpSession session=webContext.getSession();
		UserInfo  loginAdmin=(UserInfo) session.getAttribute("loginAdmin");
		
		String whereSql=" where   TEAMUID="+loginAdmin.getUid()+" or id in (select t2.TEAMID from T_AAP_TEAMUSER t2 where t2.TUSERID="+loginAdmin.getUid()+")  ";
		String orderSql="";
		List<TeamInfo> teamList=basicServices.selectList(whereSql, orderSql, TeamInfo.class);
		return teamList;
	}
	
	public List<TeamInfo> teamListByName(String teamName){
		WebContext webContext=WebContextFactory.get();
		HttpSession session=webContext.getSession();
		UserInfo  loginAdmin=(UserInfo) session.getAttribute("loginAdmin");
		 
		
		String whereSql=" where TEAMNAME like '%"+teamName+"%' and ( TEAMUID="+loginAdmin.getUid()+" or id in (select t2.TEAMID from T_AAP_TEAMUSER t2 where t2.TUSERID="+loginAdmin.getUid()+"))  ";
		String orderSql="";
		List<TeamInfo> teamList=basicServices.selectList(whereSql, orderSql, TeamInfo.class);
		return teamList;
	}
	
	public List<UserInfo> teamUserList(Integer teamId){
		String whereSql=" where UID=(select tm.TEAMUID from T_AAP_TEAM tm where tm.id="+teamId+") or " +
				" UID in (select tmu.TUSERID from T_AAP_TEAMUSER tmu where tmu.TEAMID="+teamId+")";
		String orderSql="";
		List<UserInfo> userList=basicServices.selectList(whereSql, orderSql, UserInfo.class);
		return userList;
	}
	
	
	 
	
	
}
